﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using DHQGHN.Common;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.PM0.Models.Admin
{
    public class LogModel
    {
        public long ID { get; set; }
        [Display(Name = "Tài khoản")]
        public string Account { get; set; }
        [Display(Name = "Phần mềm")]
        public string SoftWare { get; set; }
        [Display(Name = "Chức năng")]
        public string Function { get; set; }
        [Display(Name = "Dữ liệu")]
        public string Data { get; set; }
        [Display(Name = "Hành động")]
        public string Action { get; set; }
        [Display(Name = "Thời gian")]
        public DateTime ActionTime { get; set; }
        public int AppId { get; set; }
        public int RecordCount { get; set; }
        public string AppCode { get; set; }
        public string AppName { get; set; }
        public string StartDate { get; set; }
        public string EndDate { get; set; }

        public LogModel()
        {
            ID = -1;
            Account = "";
            SoftWare = "";
            Function = "";
            Data = "";
            Action = "";
            ActionTime = DateTime.MinValue;
            RecordCount = 0;
            AppId = 0;
            AppCode = "";
            AppName = "";
        }
        public LogModel(Log DALModel)
        {
            this.ID = DALModel.ID;
            this.Account = DALModel.Account;
            this.SoftWare = DALModel.SoftWare;
            this.Function = DALModel.Function;
            this.Data = DALModel.Data;
            this.Action = DALModel.Action;
            this.ActionTime = DALModel.ActionTime;
            this.RecordCount = DALModel.RecordCount;
            this.AppId = DALModel.AppId;
            this.AppName = DALModel.AppName;
            this.AppCode = DALModel.AppCode;
        }

        public DAL.Models.Admin.Log ToDALModel()
        {
            DAL.Models.Admin.Log item = new Log();
            item.ID = this.ID;
            item.Account = this.Account;
            item.SoftWare = this.SoftWare;
            item.Function = this.Function;
            item.Action = this.Action;
            item.ActionTime = this.ActionTime;
            item.Data = this.Data;
            item.RecordCount = this.RecordCount;
            item.AppId = this.AppId;
            item.StartDate = string.IsNullOrEmpty(this.StartDate) ?
                DHQGHN.DAL.Common.NullValues.Default_DateTime : 
                Utils.ConvertStringToDateTime(this.StartDate);
            item.EndDate = item.StartDate != null ?  
                (string.IsNullOrEmpty(this.EndDate) ? DateTime.Now : Utils.ConvertStringToDateTime(this.EndDate)) : 
                  DHQGHN.DAL.Common.NullValues.Default_DateTime; 

            return item;
        }
    }
}